package com.fernfx.xingtan.contacts.ui;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.fernfx.xingtan.R;
import com.fernfx.xingtan.common.base.BaseActivity;
import com.fernfx.xingtan.contacts.contract.SubmitFriendsAskContract;
import com.fernfx.xingtan.contacts.presenter.SubmitFriendsAskPresenter;
import com.fernfx.xingtan.user.AccountManager;
import com.fernfx.xingtan.utils.ToastUtil;
import com.fernfx.xingtan.utils.UIUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/8/7.
 * 发送好友请求
 */

public class SubmitFriendsAskActivity extends BaseActivity implements View.OnClickListener,SubmitFriendsAskContract.View{

    @BindView(R.id.tv_refund_project_title)
    TextView refundProjectTv;

    @BindView(R.id.friends_describe_edit)
    EditText friendsDescribEdit;

    private static final String FRIENDS_ACCOUNT = "friendsAccount";
    private String friendsAccount;

    //init presenter
    private SubmitFriendsAskContract.Presenter presenter = new SubmitFriendsAskPresenter();

    public static void start(String friendsAccount,Context context) {
        Intent intent = new Intent(context,SubmitFriendsAskActivity.class);
        intent.putExtra(FRIENDS_ACCOUNT,friendsAccount);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_chat_friends_ask;
    }

    @Override
    protected void initView() {
        //set title
        setToolbarTitle("朋友验证");
        //设置点击发送样式
        refundProjectTv.setVisibility(View.VISIBLE);
        refundProjectTv.setTextColor(UIUtil.getColor(R.color.red));
        refundProjectTv.setText("发送");
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        friendsAccount = intent.getStringExtra(FRIENDS_ACCOUNT);
        //init
        presenter.init(this);
    }

    @OnClick({R.id.tv_refund_project_title})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_refund_project_title:
                String friendsDescribText = trimEditText(friendsDescribEdit);
                //requestMap args
                requestArgsMap.clear();
                requestArgsMap.put("friendId",friendsAccount);
                requestArgsMap.put("message",friendsDescribText);
                presenter.request(requestArgsMap);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != presenter) {
            presenter.detachView();
            presenter = null;
        }
    }

    @Override
    public BaseActivity getActivity() {
        return this;
    }
}
